package exercise;

import bean.Customers;
import utils.JDBCUtils;

import java.lang.reflect.Field;
import java.sql.*;
import java.util.Scanner;


public class Exercise1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名：");
        String name = scanner.nextLine();
        System.out.println("请输入邮箱：");
        String password = scanner.nextLine();
        System.out.println("请输入生日：");
        String birthday = scanner.nextLine();

        // String sql = "SELECT id, name, password, adress, phone FROM user WHERE name='"+ name + "' AND password='" + password +"'";
        String sql = "INSERT INTO customers(cust_id, cust_name, email, birth, photo) VALUES (NULL, ?,?,?, NULL);";
        System.out.println(sql);
        update(sql, Customers.class, name, password, birthday);
    }

    public static <T> int update(String sql, Class<T> className, String... args){
        Connection connection = JDBCUtils.getConnection();
        int i=0;
        try {


            // Statement statement = connection.createStatement();
            // ResultSet resultSet = statement.executeQuery(sql);
            PreparedStatement statement = connection.prepareStatement(sql);
//            for (int i = 0; i < args.length; i++) {
//                statement.setString(i + 1, args[i]);
//            }

           i  = statement.executeUpdate();

        }
        catch (Exception e){
            e.printStackTrace();
        }

        JDBCUtils.closeConnection();
        return i;
    }
}
